<template>
	<view :class="['card-item',radius ? 'radius' : '']">
		<view class="item-head">
			<view class="left-info">
				<view class="img-wrap flex-center" @tap="toOthers(item.id)">
					<image :src="item.avatarUrl" class="avatar"></image>
				</view>
				<view class="color-nine" style="font-weight: bold;margin-left: 10px;">{{ item.nickName }}</view>
			</view>
			<text class="head-name" style="color: #CCCCCC;">{{item.createTime}}</text>
		</view>
		<view class="content" @tap="toDetails(item.id)">
			<view class="text-content">{{ item.title }}</view>
			<view class="img-wrap padding-bottom-lg" v-if="item.imgList.length == 1">
				<view class="img-box">
					<image v-for="(child, idx) in item.imgList" :key="idx" :src="child.url" class="img" @tap.stop @tap="ViewImage(idx, item.imgList)"></image>
				</view>
			</view>
			<view class="" v-if="item.vedio != ''">
				<view>
					<view class="">
						<image src="/static/timg.jpg" mode=""></image>
					</view>
				    <!-- <yfsVideo 
				    :src="item.vedio" 
				    :danmu-list="danmuList" 
				    :videoTitle="videoTitle"></yfsVideo> -->
				</view>
			</view>
			<view class="img-list padding-bottom-lg" v-if="item.imgList.length > 1">
				<view class="img-box" v-for="(child, idx) in item.imgList" :key="idx">
					<image :src="child.url" mode="widthFix" class="img" @tap.stop @tap="ViewImage(idx, item.imgList)"></image>
				</view>
			</view>
			<view class="bottom-btn padding-bottom-sm">
				<view class="btn-item flex-center">
					<image class="img" src="/static/img/diary/img_say.png" mode="widthFix"></image>
					<text>{{ item.commentNum }}</text>
				</view>
				<view class="btn-item flex-center" @tap.stop @tap="handleLike(item.id, item.isLike, item.likeNum)">
					<image class="img" v-if="!item.isLike" src="/static/img/diary/img_zan.png" mode="widthFix"></image>
					<image class="img" v-else src="/static/img/diary/img_zan_1.png" mode="widthFix"></image>
					<text>{{ item.likeNum }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import yfsVideo from '../../components/yfs-video/yfs-video.vue'
	export default {
		 components:{
		        yfsVideo
		    },
		props: {
			obj: {
				type: Object
			},
			radius:{
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				  src: 'https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20181126.mp4',
				            danmuList: [
				            ],
				            videoCurrTime:0,
				            videoTitle:"视频",
				item: this.obj,
				showPop: false,
				commentList: []
			};
		},
		watch: {
			obj(val) {
				this.list = val;
			}
		},
		methods: {
			 getTimeVideo:function(e){
			            console.log(e);
			        },
			handleFollow(id) {
				let that = this;
				that.item.follow = !that.item.follow;
			},
			toDetails(id) {
				uni.navigateTo({
					url: '/pages/faxian/details?id='+id
				});
			},
			handleLike(id, isLike, likeNum) {
				let that = this;
				console.log(id)
				if (that.item.isLike) {
					this.token = uni.getStorageSync('token')
					uni.request({
						url: this.G_base + '/api/lz/dz',
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authori-zation': 'Bearer ' + this.token
						},
						data: {
							id: id,
						},
						success: res => {
							if (res.data.status == 200) {
								if (res.data.msg == '点赞成功') {
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									})
								} else {
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									})
								}
							}
						}
					})
					that.item.likeNum--;
				} else {
					this.token = uni.getStorageSync('token')
					uni.request({
						url: this.G_base + '/api/lz/dz',
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authori-zation': 'Bearer ' + this.token
						},
						data: {
							id: id,
						},
						success: res => {
							if (res.data.status == 200) {
								if (res.data.msg == '点赞成功') {
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									})
								} else {
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									})
								}
							}
						}
					})
					that.item.likeNum++;
				}
				that.item.isLike = !that.item.isLike;
			},
			toOthers() {
				uni.navigateTo({
					url: '../../pages/mine/other'
				});
			},
			ViewImage(index, arr) {
				let list = [];
				for (let i = 0; i < arr.length; i++) {
					list.push(arr[i].url);
				}
				uni.previewImage({
					current: index,
					urls: list
				});
			}
		}
	};
</script>

<style lang="less" scoped>
	.radius{
		border-radius: 16rpx;
	}
	.card-item {
		padding: 20rpx 30rpx 0rpx;
		background-color: #ffffff;
		box-shadow: 0 20rpx 40rpx 0 rgba(0, 0, 0, 0.1);

		.item-head {
			display: flex;
			align-items: center;
			width: 100%;
			justify-content: space-between;

			.left-info {
				display: flex;
				align-items: center;

				.img-wrap {
					width: 80rpx;
					height: 80rpx;
					overflow: hidden;
					border-radius: 17%;

					.avatar {
						width: 100%;
						height: 80rpx;
					}
				}

				.head-name {
					padding-left: 40rpx;
					color: #666666;
					font-size: 32rpx;
				}
			}

			.follow-btn {
				width: 140rpx;
				height: 60rpx;
				border: 1rpx solid var(--mainColor);
				color: var(--mainColor);
				border-radius: 40rpx;
			}

			.followed {
				color: #fff;
				background: var(--activeColor);
				border: 1rpx solid var(--activeColor);
			}
		}

		.content {
			.text-content {
				padding: 40rpx 0;
				justify-content: space-between;
				color: var(--mainColor);
				font-size: 30rpx;
				text-align: justify;
			}

			.img-list {
				display: flex;
				flex-flow: row wrap;

				.img-box {
					flex: 0 0 30%;
					margin: 0 1% 1%;
					display: flex;
					align-items: center;
					justify-content: center;
					overflow: hidden;
					height: 200rpx;
					border-radius: 4px;
					background-color: #ececec;

					.img {
						width: 100%;
					}
				}
			}

			.img-wrap {
				.img-box {
					width: 100%;
					max-height: 400rpx;
					overflow: hidden;
					display: flex;
					align-items: center;
				}
			}
		}
	}

	.cont {
		--color: var(--activeColor);
		--count: 1;
	}
</style>
